<div class="view form ui-corner-all">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'collection-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<div class="row">
		<?php echo $form->LabelEx($model['collection'],'req_date'); ?>
		<?php $this->widget('zii.widgets.jui.CJuiDatePicker',
              array(
                    'model'=>$model['collection'],
                    'attribute'=>"req_date",
                    'htmlOptions'=>array('value'=>(!empty($model['collection']->in_date))?(is_numeric($model['collection']->in_date))?date('d/m/Y',$model['collection']->in_date):$model['collection']->in_date:date('d/m/Y')),
                    'options'=>array('dateFormat'=>'dd/mm/yy'),
                   )
             );
?>
	</div>
	
	<div class="row">
		<?php echo CHtml::label("Company name : ".$model['collection']->company,"company"); ?>
		<?php echo $form->dropDownList($model['collection'],'address',$model['cargo']->shipper()->getAddress(),array('style'=>'width:335px;')); ?>
	</div>
	<?php echo $form->LabelEx($model['collection'],'consignee',array('class'=>'clear')); ?>
	<hr />
	<div class="row">
		<?php echo CHtml::label("Name","consignee"); ?>
		<?php echo $form->TextField($model['collection'],'consignee',array('readonly'=>'readonly','size'=>50)); ?>
	</div>
	<div class="row">
		<?php echo CHtml::label("Address","consignee_add"); ?>
		<?php echo $form->dropDownList($model['collection'],'delivery_add',$model['cargo']->consignee()->getAddress(true),array('style'=>'width:335px;')); ?>
	</div>
	<hr />
	<div class="row">
		<?php echo $form->LabelEx($model['collection'],"pkg_id")?>
		<?php echo $form->TextField($model['detail'],"wt",array('size'=>5,'maxlength'=>11,'placeholder'=>'Weight')); ?>
        <?php echo $form->DropDownList($model['detail'], "wt_type", $model['detail']->wttype,array('style'=>'width:60px;'));?>
        <?php echo $form->TextField($model['detail'],"qty",array('size'=>5,'maxlength'=>11,'placeholder'=>'Quatity')); ?>
        <?php echo $form->DropDownList($model['detail'], "qty_type", $model['detail']->qtytype,array('style'=>'width:60px;'));?>
        <?php echo $form->TextField($model['detail'],"m3",array('size'=>5,'maxlength'=>11,'placeholder'=>'M3')); ?>
        <?php echo $form->DropDownList($model['detail'], "m3_type", $model['detail']->m3type,array('style'=>'width:60px;'));?>
	</div>
	<div class="row">
		<?php echo $form->LabelEx($model['collection'],'tools'); ?>
		<?php echo $form->TextField($model['collection'],'tools',array('maxlength'=>250,'size'=>50)); ?>
		<?php echo $form->error($model['collection'],'tools'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->LabelEx($model['collection'],'remark'); ?>
		<?php echo $form->TextArea($model['collection'],'remark',array('cols'=>39,'rows'=>3)); ?>
		<?php echo $form->error($model['collection'],'remark'); ?>
	</div>

	<div class="row buttons">
		<?php 
        	$this->widget('zii.widgets.jui.CJuiButton',array(
        		'name'=>'submit',
        		'caption'=>'Create',
        		'value'=>"create",
        	)); 
        ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
<?php
$cs = Yii::app()->ClientScript;
$getCompanyInfoURL = CHtml::normalizeUrl(array('company/getInfo'));
$CargoViewURL = CHtml::normalizeUrl(array('cargo/view','id'=>$model['cargo']->id));
$getAddressUrl = CHtml::normalizeUrl(array('company/getaddress'));
$getContactUrl = CHtml::normalizeUrl(array('company/getcontact'));
$script =<<<EOD
$.collection_create_form = {
	afterSubmit:function(data){
		window.location = "$CargoViewURL";
	}
};
$('#collection-form [type=submit]').click(function(){
	var form = $.extend($.simplelogform,$.collection_create_form);
	form.Submit($('#collection-form'));
	return false;
});
$('select#collection_attn, select#collection_delivery_attn').change(function(){
	if($(this).val() == "Others"){
		var html = "<input size='50' name='"+$(this).attr('name')+"' id='"+$(this).attr('id')+"' placeholder='Please specify' />";
		$(this).replaceWith(html);
	}
});
$('select#collection_address, select#collection_delivery_add').change(function(){
	if($(this).val() == "Others"){
		var html = "<textarea cols='39' rows='3' name='"+$(this).attr('name')+"' id='"+$(this).attr('id')+"' placeholder='Please specify' />";
		$(this).replaceWith(html);
	}
});
EOD;
$cs->registerScript('collection#create#form',$script);
?>